package utils
{
	import flash.display.Graphics;
	import flash.geom.Point;

	/**
	 *扇形类
	 * @author Administrator
	 *
	 */
	public class SectorUtil
	{
		public function SectorUtil()
		{
		}

		public static const LEFT : uint = 180;
		public static const BOTTOM : uint = 90;
		public static const RIGTH : uint = 0;
		public static const TOP : uint = 270;

		/**
		 *
		 * @param graphics
		 * @param x
		 * @param y
		 * @param radius 半径
		 * @param anlge  角度
		 *
		 */
		public static function drawSector( graphics : Graphics, x : Number, y : Number, radius : Number, angle : int, pos : int = 270 ) : void
		{
			if ( angle > 360 )
				angle %= 360;

			calcXY( pos * perRadians, radius, x, y, startPoint );
			calcXY(( pos + angle ) * perRadians, radius, x, y, endPoint );

			graphics.moveTo( endPoint.x, endPoint.y );
			graphics.lineTo( x, y );
			graphics.lineTo( startPoint.x, startPoint.y );

			var sign : int = angle > 0 ? 1 : -1;
			var totalAngle : uint = Math.abs( angle );
			var radians : Number;

			for ( var i : uint = 1; i <= totalAngle; ++i )
			{
				radians = ( i * sign + pos ) * perRadians;
				calcXY( radians, radius, x, y, endPoint );
				graphics.lineTo( endPoint.x, endPoint.y );
			}

		}

		private static function calcXY( radians : Number, radius : Number, x : Number, y : Number, point : Point ) : void
		{
			point.x = x + Math.cos( radians ) * radius;
			point.y = y + Math.sin( radians ) * radius;
		}

		private static var startPoint : Point = new Point;
		private static var endPoint : Point = new Point;
		private static var perRadians : Number = Math.PI / 180;
	}
}
